import { httpUrl } from 'api/config';
import { ajaxPost } from 'api/axios';
import { changeDataType } from 'common/js/util';

export function getList(page = 1) {
	let url = `${httpUrl}/api/list`;
	
	let data = {
		page: page,
		rows: 10
	};
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function updateList(obj) {
	let url = `${httpUrl}/api/save`;
	
	let data = obj
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function deleteList(id) {
	let url = `${httpUrl}/comm/Api/delete`;
	
	let data = {
		id: id
	}
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}
